#include "KDindex.h"
const int dim=3;
Index <L2<float> >* createIndex()
{
    Index <L2<float> > * idx;
    Matrix<float> dataset(new float[1*dim],1 , dim);
    dataset[0][0]=-10000;
    dataset[0][1]=-10000;
    dataset[0][2]=-10000;
    idx=new Index <L2<float> > (dataset,KDTreeIndexParams(1));
    idx->buildIndex();
    idx->removePoint(0);
    return idx;
}

void addPoint(Index <L2<float> >* idx,double x,double y,double z)
{
    Matrix<float> dataset(new float[1*dim],1 , dim);
    dataset[0][0]=x;
    dataset[0][1]=y;
    dataset[0][2]=z;
    idx->addPoints(dataset);
}

void getNearest_point(Index <L2<float> >* idx,double x,double y,double z,int maxResults, vector<vector<int>> &indices)
{
    Matrix<float> dataset(new float[1*dim],1 , dim);
    dataset[0][0]=x;
    dataset[0][1]=y;
    dataset[0][2]=z;
    std::vector<std::vector<float>> dists;
    idx->knnSearch(dataset, indices, dists, maxResults, SearchParams(128));
}

void getNearest_point_radius(Index <L2<float> >* idx,double x,double y,double z,int maxResults, double dist, vector<vector<int>> &indices)
{
    Matrix<float> dataset(new float[1*dim],1 , dim);
    dataset[0][0]=x;
    dataset[0][1]=y;
    dataset[0][2]=z;
    std::vector<std::vector<float>> dists;
    idx->radiusSearch(dataset, indices, dists, dist, SearchParams(128));
}
